package jjn.round1;

/**
 * @author Jiang Jining
 * @since 2022-12-05 22:11
 */
public class LeetCode1796_SecondLargestDigitInAString {
    public int secondHighest(String s) {
        if (s == null || s.length() == 0) {
            return -1;
        }
        int biggest = -1, secondBiggest = -1;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (Character.isDigit(c)) {
                int current = c - '0';
                if (current > biggest) {
                    secondBiggest = biggest;
                    biggest = current;
                    continue;
                }
                if (current == biggest) {
                    continue;
                }
                if (current > secondBiggest) {
                    secondBiggest = current;
                }
            }
        }
        return secondBiggest;
    }
}
